/**
 * @file ${relativeFile}
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @brief
 * @version 1.0
 * @date 2022-05-14
 *
 * @copyright Copyright (c) 2022
 *
 **/

#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int w[N];
int dp[N][N];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i], w[i] += w[i - 1];
  memset(dp, 0x3f, sizeof dp);
  for (int len = 1; len <= n; ++len) {
    for (int i = 1; i + len - 1 <= n; ++i) {
      int j = i + len - 1;  // 取 [l, r] 区间
      if (len == 1) {
        dp[i][j] = 0;
      } else {
        for (int k = i; k < j; ++k) {
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + w[j] - w[i - 1]);
        }
      }
    }
  }
  cout << dp[1][n] << endl;
}
